<?php
namespace Mageplaza\HelloWorld\Controller\Index;

class Test extends \Magento\Framework\App\Action\Action
{
    protected $_pageFactory;

    protected $_postFactory;

    public function __construct(
        \Magento\Framework\App\Action\Context $context,
        \Magento\Framework\View\Result\PageFactory $pageFactory,
        \Mageplaza\HelloWorld\Model\PostFactory $postFactory
    )
    {
        $this->_pageFactory = $pageFactory;
        $this->_postFactory = $postFactory;
        return parent::__construct($context);
    }

    public function execute()
    {
        $post = $this->_postFactory->create();
        $collection = $post->getCollection();
        echo "xxxxxxxxxxxxxxx";
        echo "<pre>";
        $m = $collection->getConnection()->query("select * from catalog_product_bundle_option ")->fetchAll(); // 查询数据
       //接发的链接发来；就放大； 法律放假啊
        $s = $collection->getSelectSql(true);
        var_dump($collection->count()); //获取总数

        foreach($collection as $item){
            echo "<pre>";
            print_r($item->getData());
            echo "</pre>";
        }
        /*该方法指在重写控制其中数据的的数据*/
        $textDisplay = new \Magento\Framework\DataObject(['name'=>'xxxxxxxxxxxx']);
        $this->_eventManager->dispatch("mageplaza_helloworld_display_text",['mp_name'=>$textDisplay]);
        echo $textDisplay->getName();
        exit;
        //return $this->_pageFactory->create();
    }
}